import {
  getToken
} from '@/utils/getToken'

import store from '../store'

const Token = getToken()

const loginUserPermission = store.state.user.loginUserPermission
let IndexPath = ''
if (loginUserPermission && loginUserPermission.length >= 1) {
  IndexPath = loginUserPermission[0].uri || '/pms/index'
} else {
  IndexPath = '/pms/index'
}

let publicRoutes = [{
  path: '/',
  redirect: Token ? IndexPath : '/login'
}, {
  path: '/login',
  name: 'LoginPage',
  component: () => import('@/pages/login.vue'),
  meta: {
    icon: '',
    title: '登录'
  }
}, {
  path: '/404',
  name: '404',
  component: () => import('@/pages/error.vue'),
  meta: {
    title: '404',
    hidden: true
  }
}, {
  path: '*',
  redirect: '/404',
  meta: {
    hidden: true
  }
}]

if (process.env.NODE_ENV !== 'production') {
  publicRoutes.push({
    path: '/test',
    name: 'TestPage',
    component: () => import('@/pages/test.vue'),
    meta: {
      icon: '',
      title: '测试'
    }
  })
}

// 公开的路由
export default publicRoutes
